package ru.develbureau.server.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class ErrorTag extends SimpleTagSupport {
	private static final long serialVersionUID = 1L;
	String val = null;
	
	private static final String DIV = "<div class=\"error\">ERROR</div>";
	private static final String INSERT_HERE = "ERROR";
	
	public void doTag() throws JspException {
		try{
			PageContext pageContext = (PageContext) getJspContext(); 
		    JspWriter out = pageContext.getOut(); 
			if(val!=null){
				String outputDiv = DIV.replace(INSERT_HERE, val);
				out.println(outputDiv);
			}
		}catch (Exception e) {

		}
	}
	
	public void setValue(Object value){
		if(value!=null && value instanceof String){
			String t = (String)value;
			if(t.trim().length()>0){
				val = t;
			}
		}
	}
	
	public Object getValue(){
		return val;
	}

}
